<?php 
$itm_cnt = 0;
$edit = 'none';
include('../../Connections/KRAPPERCON.php');
$combo = '';
include('../../Query_Min/getAlmacenes.php');
$combo_alm = $combo;
$find = false;
$combo_um = '';
include('../../Query_Min/getUMedidas.php');
$oper = getVal('oper');

if ($oper == 'view'){
$orden = getVal('orden');
$sql_oc = "call sp_getSPDet(".$orden.");";
	$res = $mysqli->query($sql_oc) or die($mysqli->error.__LINE__);

	if ($res){
		$find = true;
		while($row = $res->fetch_assoc()){
		/*
			if ($itm_cnt==0){
				$edit = '';
				$disable2 = "disabled";
			// Obtener Datos de cabecera
				$fecdoc = $row['OrdenFecDoc'];
				$feccre = $row['OrdenFecCre'];
				$userid  = $row['UserID'];
				$fecent = $row['OrdenFecEnt'];
				$ocprov = $row['ProveedID'];
				$ocref = $row['OrdenRef'];
				$ocmonto = $row['OrdenMonto'];
				$ocldoc = $row['ClaDocID'];
			}
			*/
			$itm_cnt = $itm_cnt + 1;
			$sp_posn[] = $row['SolPedItm'];
			//$oc_dcto[] = $row['DetOrdDct'];
			$sp_cods[] = $row['ArticuloID'];
			$sp_noms[] = $row['ArticuloTxt'];
			$sp_prun[] = $row['PreUM'];
			$sp_qtpe[] = $row['CtdUM'];
			$sp_qtat[] = $row['CtdCons'];
			$sp_qtfi[] = $row['CtdFinal'];
			$sp_unm[] = $row['UniMed'];
			$sp_nets[] = $row['PreNet'];
			$sp_brut[] = $row['PreBru'];
			$sp_almc[] = $row['AlmacenID'];
			//$oc_cent[] = $row['CentroID'];
			$sp_dels[] = $row['StsItm'];
		}
		
		include ('OperItmSolp.php');
		
		$res->close();
		
			$mysqli->check_result();
	}
}
elseif ($oper == 'hist') {
$orden = getVal('orden');
$posic = getVal('posic');
?>
    <table width="100%" border="1" cellspacing="0" cellpadding="0" rules="all">
<thead>
  <tr>
    <th>Factura</th>
    <th>Fecha</th>
    <th>Usuario</th>
    <th>Cantidad</th>
    <th>Neto</th>
    <th>Almacen</th>
  </tr>
  </thead>
  <tbody>
    <?php 
if ($orden > 0 and $posic > 0){
$tot = 0;
$totq = 0;
	$sql = "call sp_getHistDocOC('".$orden."','".$posic."');";
	$res = $mysqli->query($sql);
		if ($res){
			while($row = $res->fetch_assoc()){
?>

  <tr>
    <td><a href="#"><?php echo $row['FactCompID']; ?></a></td>
    <td><?php echo $row['FactCompFeCr']; ?></td>
    <td><?php echo $row['UserID']; ?></td>
    <td class="qt"><?php echo $row['FactCompQta']; ?></td>
    <td class="qt"><?php echo $row['FactCompNeto']; ?></td>
    <td><?php echo $row['AlmacenID']; ?></td>
  </tr>
<?php 				
		$tot += $row['FactCompNeto'];
		$totq += $row['FactCompQta']; 
			}
			$res->close();
			
				$mysqli->check_result();
		}
	}
?>
  </tbody>
  <tfoot>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th class="qt"><?php echo $totq; ?></th>
    <th class="qt"><?php echo number_format($tot,2); ?></th>
    <th class="">&nbsp;</th>
  </tr>
  </tfoot>
</table>
<?php 	
}
?>
